import { createBrowserRouter, Link } from "react-router-dom";
import { ErrorBlock } from "antd-mobile";
const lazyHome = async () => {
  const { default: Home,loader } = await import("../pages/tabs/Home");
  return {
    element: <Home />,
    loader
  };
};
let router = createBrowserRouter([
  {
    path: "/",
    async lazy() {
      const { default: App } = await import("../App");
      return {
        element: <App />,
      };
    },
    children: [
      {
        index: true,
        lazy: lazyHome,
      },
      {
        path: "home",
        lazy: lazyHome,
      },
      {
        path: "video",
        async lazy() {
          const { default: Video } = await import("../pages/tabs/Video");
          return {
            element: <Video />,
          };
        },
      },
      {
        path: "end",
        async lazy() {
          const { default: End } = await import("../pages/tabs/End");
          return {
            element: <End />,
          };
        },
      },
      {
        path: "chat",
        async lazy() {
          const { default: Chat } = await import("../pages/tabs/Chat");
          return {
            element: <Chat />,
          };
        },
      },
      {
        path: "my",
        async lazy() {
          const { default: My } = await import("../pages/tabs/My");
          return {
            element: <My />,
          };
        },
      },
    ],
  },
  {
    path: "/city/:type",
    async lazy() {
      const { default: City,loader } = await import("../pages/city/index");
      return {
        element: <City />,
        loader
      };
    },
  },
  {
    path: "/list",
    async lazy() {
      const { default: List,loader } = await import("../pages/list/index");
      return {
        element: <List />,
        loader
      };
    },
  },
  {
    path: "/detail/:id",
    async lazy() {
      const { default: Detail,loader } = await import("../pages/detail/index");
      return {
        element: <Detail />,
        loader
      };
    },
  },
  {
    path: "/reg",
    async lazy() {
      const { default: Reg } = await import("../pages/auth/reg");
      return {
        element: <Reg />,
      };
    },
  },
  {
    path: "/login",
    async lazy() {
      const { default: Login } = await import("../pages/auth/login");
      return {
        element: <Login />,
      };
    },
  },
  {
    path: "*",
    element: (
      <ErrorBlock fullPage description={<Link to="/home">去首页</Link>} />
    ),
  },
]);
export default router;
